import { DataTypes, Model } from "sequelize";
import sequelize from "../sequelize";
import { getRandomInt } from "@helpers";

export class EmailCode extends Model {
    declare id: number;
    declare email: string;
    declare code: string;
}

EmailCode.init(
    {
        id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            primaryKey: true,
            autoIncrement: true,
            unique: true,
        },
        email: { type: DataTypes.STRING, allowNull: false },
        code: {
            type: DataTypes.STRING,
            defaultValue: () => {
                return getRandomInt(100_000, 999_999);
            },
        },
    },
    {
        tableName: "email-codes",
        sequelize,
    }
);
